Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity docs #171

Open
wants to merge 81 commits into
base: main
Choose a base branch
from

Conversation

IchHabeHunger54
Copy link
Member

@IchHabeHunger54 IchHabeHunger54 commented Oct 3, 2024

Adds some long-needed entity documentation. Supersedes #15 and #95 . Closes #90 . This PR:

  • Adds articles about the following:
    • Entities in general
    • Data and networking in the context of entities
    • The LivingEntity, Mob and Player classes, along with their subclasses
    • Attributes and AttributeModifiers
    • Entity renderers and entity models
  • Removes the Entities article in the Networking section, in favor of the new Data and Networking article
  • Updates the Interaction Pipeline article with left-click and middle-click behavior, and also renames it to just Interactions
  • Adds an explanation for how block breaking speed is calculated, including how the various attributes affect this
    • Also does some reformatting in the blocks article, while we're at it
  • Adds and adjusts links to the new Entities section as necessary
  • Adds a styleguide for Mermaid class diagrams to the Contributing doc
  • Explicitly leaves WIP markers for pathfinding, goals and brains, as well as animations, as these deserve their own PR(s)

Preview URL: https://pr-171.neoforged-docs-previews.pages.dev

IchHabeHunger54 and others added 30 commits January 29, 2024 18:04
Co-authored-by: ChampionAsh5357 <[email protected]>
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) December 2, 2024 16:15 Active
Copy link
Member

@XFactHD XFactHD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass over the changes, still have to do the 4 largest files.

docs/blocks/index.md Outdated Show resolved Hide resolved
docs/entities/data.md Outdated Show resolved Hide resolved
docs/entities/data.md Outdated Show resolved Hide resolved
docs/entities/data.md Outdated Show resolved Hide resolved
docs/entities/data.md Outdated Show resolved Hide resolved
Comment on lines +75 to +76
EntityRenderer-->ArrowRenderer;
EntityRenderer-->LivingEntityRenderer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EntityRenderer-->ArrowRenderer;
EntityRenderer-->LivingEntityRenderer;
EntityRenderer-->LivingEntityRenderer;
EntityRenderer-->ArrowRenderer;

These should be switched around to avoid the arrow from LivingEntityRenderer to ArmorStandRenderer going through the ArrowRenderer node

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this makes the arrow go through the AbstractMinecartRenderer instead. I'm afraid there is no easy way of solving this.

docs/entities/renderer.md Outdated Show resolved Hide resolved
docs/entities/renderer.md Outdated Show resolved Hide resolved
docs/entities/renderer.md Outdated Show resolved Hide resolved
docs/entities/data.md Show resolved Hide resolved
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) December 14, 2024 17:12 Active
docs/entities/index.md Outdated Show resolved Hide resolved
docs/entities/data.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ChampionAsh5357 ChampionAsh5357 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the requested feedback. Still a few WIP sections, so I'm wondering why it was brought out of draft early.

docs/blocks/index.md Outdated Show resolved Hide resolved
@@ -120,6 +120,7 @@ graph TD;
PlayerEvent-->CanPlayerSleepEvent;

class Event,BlockEvent,EntityEvent,LivingEvent,PlayerEvent red;
class BlockDropsEvent,CanPlayerSleepEvent blue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this in an entity docs PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly because this is the first PR that really makes use of Mermaid diagrams. I adopted the style guide of red -> abstract, blue -> non-abstract, and applied it to the only other diagram we had while I was at it.

docs/entities/attributes.md Show resolved Hide resolved
docs/entities/attributes.md Outdated Show resolved Hide resolved
docs/entities/attributes.md Outdated Show resolved Hide resolved
docs/entities/livingentity.md Outdated Show resolved Hide resolved
Comment on lines 156 to 158
Natural spawning is performed every tick for entities where `MobCategory#isFriendly()` is true, and every 400 ticks (\= 20 seconds) for entities where `MobCategory#isFriendly()` is false. If `MobCategory#isPersistent()` returns true, this process additionally also happens on chunk generation.

For each chunk and mob category, it is checked whether there are less than `MobCategory#getMaxInstancesPerChunk() * loadedChunks / 289` in the world. Additionally, for each chunk, it is required that there are less than `MobCategory#getMaxInstancesPerChunk()` entities of that `MobCategory` near at least one player (near means that the distance between mob and player \<\= 128) for spawning of that `MobCategory` to occur.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be best to frame this with an example to get the actual numbers for each.

docs/entities/livingentity.md Outdated Show resolved Hide resolved
docs/entities/renderer.md Outdated Show resolved Hide resolved
docs/entities/renderer.md Outdated Show resolved Hide resolved
@neoforged-automation neoforged-automation bot added the needs rebase This Pull Request needs to be rebased before being merged label Jan 10, 2025
@neoforged-automation
Copy link

@IchHabeHunger54, this pull request has conflicts, please resolve them for this PR to move forward.

# Conflicts:
#	docs/resources/client/models/bakedmodel.md
#	docs/resources/server/conditions.md
@neoforged-automation neoforged-automation bot removed the needs rebase This Pull Request needs to be rebased before being merged label Jan 10, 2025
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) January 10, 2025 23:31 Active
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) February 4, 2025 12:52 Active
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) February 6, 2025 13:49 Active
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) February 6, 2025 15:27 Active
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) February 6, 2025 16:22 Active
@neoforged-pages-deployments neoforged-pages-deployments bot deployed to neoforged-docs-previews (Preview) February 6, 2025 16:44 Active
Copy link
Contributor

@ChampionAsh5357 ChampionAsh5357 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I give you...more comments!

```java
// This will return the tool's mining speed, or 1 if the held item is either empty, not a tool,
// or not applicable for the block being broken.
float destroySpeed = item.getDestroySpeed();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this takes in the BlockState to determine the destroy speed.

Comment on lines +294 to +295
if (player.hasEffect(MobEffects.DIG_SPEED)) { destroySpeed *= ...; }
if (player.hasEffect(MobEffects.CONDUIT_POWER)) { destroySpeed *= ...; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is partially wrong. It applies the maximum amplifier from dig speed and conduit power before doing some math stuff.

| `nametag_distance` | `NAMETAG_DISTANCE` | `[0,32]` | 32 | How far the nametag of the entity will be visible, in blocks. |
| `swim_speed` | `SWIM_SPEED` | `[0,1024]` | 1 | A movement speed multiplier that is applied when the entity is underwater. This is applied independently from `minecraft:water_movement_efficiency`. |

## Default Attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should also include the EntityAttributeModificationEvent for adding new attributes to existing entities.

And that's it! Just don't forget to register your `DeferredRegister` to the mod bus, and off you go.

:::info
We use `Holder<Attribute>` here, instead of `Supplier<RangedAttribute>` like with many other registered objects, as it makes working with entities a lot easier (most entity methods expect `Holder<Attribute>`s). If, for some reason, you need a `Supplier<RangedAttribute>` (or a supplier of any other subclass of `Attribute`), you should use `DeferredHolder<Attribute, RangedAttribute>` as the type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify to use the explicit type you're using, since not everyone would use the RangedAttribute.

docs/entities/data.md Show resolved Hide resolved
if (renderer != null) {
// Add the layer to the renderer. Like above, construct a new MyRenderLayer.
// The EntityModelSet can be retrieved from the event through #getEntityModels.
renderer.addLayer(new MyRenderLayer(renderer, event.getEntityModels()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not compile due to the generics.

// Get the associated PlayerRenderer.
if (event.getSkin(skin) instanceof PlayerRenderer playerRenderer) {
// Add the layer to the renderer.
playerRenderer.addLayer(new MyRenderLayer(playerRenderer, event.getEntityModels()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not compile due to the generics differing between the layer and the renderer.


## Animations

NeoForge adds an optional system that allows entity animations to be defined in JSON files, similar to third-party libraries such as [GeckoLib][geckolib]. Animations are defined in JSON files located at `assets/<namespace>/neoforge/animations/entity/<path>.json` (so for the [resource location][rl] `examplemod:example`, the file would be located at `assets/examplemod/neoforge/animations/entity/example.json`). The format of an animation file is as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically not a complete NeoForge system. Animation definitions is a vanilla system for animations using keyframes and interpolation data. What NeoForge adds is the ability is to define these via JSON. That might be what this sentence is saying, but it's a bit confusing.

{
// The name of the part to be animated.
// Must match the name of a part defined in your LayerDefinition (see above).
"bone": "head",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are multiple matches, it will just pick the first one it finds, which will always be a depth-first search iirc.

// A list of keyframes for the part.
"keyframes": [
{
// The timestamp of the keyframe. Should be between 0 and the animation length.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp is also in seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition Adding or rewriting information. large Major additions or changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entities - Simply Complicated
5 participants